package br.com.visagio.aulabigdata.models;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.solr.client.solrj.beans.Field;

import twitter4j.Status;
import br.com.visagio.aulabigdata.util.TwitterUtil;

@Entity
@Table(name = "tweet")
public class Tweet implements Serializable{
	
	private static final long serialVersionUID = 8371598377891281610L;

	@Field
	@Column
	private Date createdAt;
	
	@Field
	@Column
	private boolean retweeted;
	
	@Field
	@Column
	private int retweetCount;
	
	//@Field
	@Transient
	private Object user;
	
	@Field
	@Id
	@Column
	private long id;
	
	@Field
	@Column
	private String text;
	
	@Column
	private String source;

	@Field
	@Column
	private double latitude;

	@Field
	@Column
	private double longitude;

	@Field
	@Transient
	private String[] hashtags;
	
	public Tweet(){
		
	}
	
	public Tweet(Status tweet){
		this.createdAt = tweet.getCreatedAt();
		this.id = tweet.getId();
		this.retweetCount = tweet.getRetweetCount();
		this.retweeted = tweet.isRetweeted();
		this.source = tweet.getSource();
		this.text = tweet.getText();
		this.user = tweet.getUser().getName();
		this.setHashtags(TwitterUtil.getHashtagArray(tweet.getHashtagEntities()));
		if(tweet.getGeoLocation() != null){
			this.setLatitude(tweet.getGeoLocation().getLatitude());
			this.setLongitude(tweet.getGeoLocation().getLongitude());
		}
		
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public boolean isRetweeted() {
		return retweeted;
	}

	public void setRetweeted(boolean retweeted) {
		this.retweeted = retweeted;
	}

	public int getRetweetCount() {
		return retweetCount;
	}

	public void setRetweetCount(int retweetCount) {
		this.retweetCount = retweetCount;
	}

	public Object getUser() {
		return user;
	}

	public void setUser(Object user) {
		this.user = user;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public String[] getHashtags() {
		return hashtags;
	}

	public void setHashtags(String[] hashtags) {
		this.hashtags = hashtags;
	}
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		return sb.append("Id=").append(getId()).append("  Data criação=").append(getCreatedAt()).append("\n").append("\tTexto:=").append(getText().substring(0, (getText().length()<150 ? getText().length():150)-1)).append("...\n").toString();
	}

}
